Sqoop Export with Joins

 
TO IMPORT THE DATA FROM “RDBMS” to “HDFS”

Free from Query Imports
Sqoop can also import the result set of an arbitrary SQL query. Instead of using the --table, --columns and --where arguments, you can specify a SQL statement with the --query argument.

    When importing a free-form query, you must specify a destination directory with --target-dir

If you want to import the results of a query in parallel, then each map task will need to execute a copy of the query, with results partitioned by bounding conditions inferred by Sqoop. Your query must include the token $CONDITIONS which each Sqoop process will replace with a unique condition expression. You must also select a splitting column with --split-by.

sqoop import --connect jdbc:mysql://localhost:3306/dwdev --username root --password cloudera --query "select e.empid,ename,esal,e.deptid,dname,dloc from emp e inner JOIN dept d ON (e. deptid = d.deptid) AND \$CONDITIONS" -m 1 --target-dir=/sqoop/data
Inner Join
sqoop import --connect jdbc:mysql://localhost:3306/dwdev --username root --password cloudera --query "select e.empid,ename,esal,e.deptid,dname,dloc from emp e inner JOIN dept d ON (e. deptid = d.deptid) AND \$CONDITIONS" -m 1 --target-dir=/sqoop/INNERJOIN;

Left Join
sqoop import ---connect jdbc:mysql://localhost:3306/dwdev --username root --password cloudera --query "select e.empid,ename,esal,deptid,dname,dloc from emp e LEFT OUTER JOIN dept d ON (e.deptid = d.deptid) AND \$CONDITIONS" -m 1 –target-dir=/sqoop/LEFTJOIN;

Left Join
sqoop import --connect jdbc:mysql://localhost:3306/tetradb --username root --password Tetra@123 --query "select e.empid,ename,esal,deptid,dname,dloc from emp e RIGHT OUTER JOIN dept d ON (e.deptid = d.deptid) AND \$CONDITIONS" -m 1 –target-dir=/sqoop/RIGHTJOIN;

No comments:

Post a Comment